package com.igeek.yygh.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.igeek.yygh.model.cmn.Dict;
import com.igeek.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @Author zengxiangjun
 * @Date 2022/8/5  20:44 MyAnalysisEventListener
 */

public class MyAnalysisEventListener extends AnalysisEventListener<DictEeVo> {
    //等价于操作DictMapper
    private BaseMapper<Dict> baseMapper;

    public MyAnalysisEventListener(BaseMapper<Dict> baseMapper) {
        this.baseMapper = baseMapper;
    }

    //一行行读取Excel中数据 -> 插入至数据库中
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo, dict);
        //插入Dict数据，至数据库
        baseMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
